package cn.gcjxsc.service.mall;

import cn.gcjxsc.common.consts.OrderDiscr;
import cn.gcjxsc.entity.mall.BaseOrder;
import cn.gcjxsc.entity.mall.ShoppingOrderExt;
import cn.gcjxsc.repository.order.BaseOrderRepository;
import cn.gcjxsc.repository.order.ShoppingOrderExtRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * @author pumbaa
 * @since 1.0
 */
@Service
public class OrderService {
    @Autowired
    private BaseOrderRepository orderRepository;
    @Autowired
    private ShoppingOrderExtRepository orderExtRepository;

    @Transactional
    public BaseOrder saveOrUpdate(BaseOrder order) {
        return orderRepository.save(order);
    }

    public BaseOrder findRechargeOrderBySn(String sn) {
        return orderRepository.findBySnAndDiscr(sn, OrderDiscr.RECHARGE_ORDER);
    }

    /**
     * 根据订单号查询购物订单
     * @param sn 订单号
     * @return
     */
    public BaseOrder findShoppingOrderBySn(String sn){
        return orderRepository.findBySnAndDiscr(sn, OrderDiscr.SHOPPING_ORDER);
    }

    /**
     *
     * @param orderId
     * @return
     */
    public ShoppingOrderExt findExtByOrderId(Integer orderId) {
        return orderExtRepository.findByOrderId(orderId);
    }
}
